﻿Imports System.Data.OleDb
Partial Public Class showTags
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim tagCountSql As String = "SELECT papersweeksandtags.Tag, Count(*) AS TagCount FROM papersweeksandtags GROUP BY papersweeksandtags.Tag"
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("mobilestandardsdb").ConnectionString)
        oleDbConn.Open()
        Dim tagCountCmd As New OleDbCommand(tagCountSql, oleDbConn)
        Dim tagCountReader = tagCountCmd.ExecuteReader()
        Dim tagHash As New Hashtable
        Dim maxTagCt As Integer = 0
        Dim minTagCt As Integer = 0
        If tagCountReader.HasRows() Then
            While tagCountReader.Read()
                Response.Write(tagCountReader("Tag") & " " & tagCountReader("TagCount"))
                tagHash.Add(tagCountReader("Tag"), CInt(tagCountReader("TagCount")))
                If minTagCt = 0 Then minTagCt = CInt(tagCountReader("TagCount"))
                If minTagCt > CInt(tagCountReader("TagCount")) Then minTagCt = CInt(tagCountReader("TagCount"))
                If maxTagCt < CInt(tagCountReader("TagCount")) Then maxTagCt = CInt(tagCountReader("TagCount"))
            End While
        End If
        Dim fontOptions() As String = {"xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"}
        Dim scaleUnit As Decimal = (maxTagCt - minTagCt + 1) / Convert.ToDecimal(fontOptions.Length)

        Dim tagCloudHtml As String = ""
        Dim homepageStem As String = "mobileStandards.aspx?"
        For Each tmpTag In tagHash
            Dim scaleValue As Integer = Math.Truncate((tmpTag.value - minTagCt) / scaleUnit)
            tagCloudHtml = tagCloudHtml & String.Format("<A HREF = ""{0}"" style=""font-size:{1};"">{2}</A>", homepageStem & "tag=" & tmpTag.key, fontOptions(scaleValue), tmpTag.key)
        Next
        phTagContainer.Controls.Add(New LiteralControl(tagCloudHtml))

    End Sub


End Class